﻿using Appliaction.Dto.Base_Manage;
using Appliaction.IAppServices.Base_Manage;
using AutoMapper;
using EFCore.Repositorys.Inv;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class UserController : ControllerBase
    {
        private readonly IUserService userService;
        private readonly IMapper mapper;

        public UserController(IUserService userService,IMapper mapper)
        {
            this.userService = userService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 查询全部用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetUsersAsync(int dept, string? name)
        {
            return new JsonResult(await userService.GetUsersAsync(dept,name));
        }

        /// <summary>
        /// 根据用户名和部门分页查询用户和角色信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dept_id"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSys_UsersAsync(string? name, int dept_id, int currentPage, int pageSize)
        {
            return new JsonResult(await userService.GetSys_UsersAsync(name,dept_id,currentPage,pageSize));
        }

        /// <summary>
        /// 根据用户名和部门查询用户总数S
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dept_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSys_UsersCountAsync(string? name, int dept_id)
        {
            return new JsonResult(await userService.GetSys_UsersCountAsync(name,dept_id));
        }

        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="userAddDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Sys_UserAddAsync(UserAddDto userAddDto)
        {
            return new JsonResult(await userService.Sys_UserAddAsync(userAddDto));
        }

        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="userUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sys_UserUpdateAsync(UserUpdateDto userUpdateDto)
        {
            return new JsonResult(await userService.Sys_UserUpdateAsync(userUpdateDto));
        }

        /// <summary>
        /// 逻辑删除用户信息
        /// </summary>
        /// <param name="userDeleteDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sys_UserDeleteAsync(UserDeleteDto userDeleteDto)
        {
            return new JsonResult(await userService.Sys_UserDeleteAsync(userDeleteDto));
        }


      
    }
}
